package com.zgc.simpleholiday.utils;

import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ClassUtils;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;

public class FilePathUtil {
    public static String getFilePath(String fileName) {
        return Objects.requireNonNull(Objects.requireNonNull(ClassUtils.getDefaultClassLoader()).getResource("")).getPath() + File.separator  + fileName + ".ser";
    }

    public static String getFilePath2(String fileName) throws IOException {
        return ResourceUtils.getFile("classpath:static" ).getPath()+ File.separator + fileName + ".ser";
    }


    public static InputStream getFileInputStream(String fileName) throws IOException {
        return new ClassPathResource("static" + File.separator + fileName + ".ser").getInputStream();
    }
}
